package java0108;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

// 服务器端
public class Java04 {
    // (4)网络 + IO
    // 客户端   ——>   服务器
    // navicat ——> Mysql
}

// 服务器
class Server {
    public static void main(String[] args) throws IOException {
        // 创建一个服务器套接字：ip地址、port端口
        ServerSocket serverSocket = new ServerSocket(8081);

        while (true) {
            // 创建套接字：接受请求
            Socket socket = serverSocket.accept();
            // 从套接字中获取输入流
            InputStream inputStream = socket.getInputStream();
            byte[] arr = new byte[1024];
            int len = inputStream.read(arr);
            System.out.println(new String(arr, 0, len));
        }
    }
}

// 客户端
class Client {
    public static void main(String[] args) throws IOException {
        // 创建套接字对象：需要指定ip和port
        // ipconfig、192.168.1.35
        Socket socket = new Socket("192.168.1.35", 8081);
        OutputStream outputStream = socket.getOutputStream();
        outputStream.write("你好jack".getBytes());
    }
}

